<?php

class Admin_mis extends CI_Controller {

    function __construct() {
        parent::__construct();
        $this->load->helper(array('form', 'url', 'date'));
        $this->load->library(array('session', "table", "pagination", 'form_validation'));

        if ($this->session->userdata("admin") === false) {
            redirect("admin/index/You must login first");
        } else if ($this->session->userdata("admin") == FALSE) {//not logged in as an admin?
            $func = $this->uri->segment(2);
            if (preg_match("/^delete/", $func)) {//then you cant delete
                redirect("admin/index/You must login as an admin first");
            }
        }


        $this->load->model("appointments_model", "", TRUE);
        $this->load->model("innovations_model", "", TRUE);
        $this->load->model("documents_model", "", TRUE);
        $this->load->model("settings/document_types_model", "", TRUE);
        $this->load->model("settings/kim_model", "", TRUE);
        $this->load->model("settings/clients_model", "", TRUE);
        $this->load->model("settings/sbus_model", "", TRUE);
        $this->load->model("letters_model", "", TRUE);
        $this->load->model("debts_model", "", TRUE);
        $this->load->model("proposals_model", "", TRUE);
        $this->load->model("assets_model", "", TRUE);
        $this->load->model("bids_model", "", TRUE);
        $this->load->model("concepts_model", "", TRUE);
        $this->load->model("opis_model", "", TRUE);
        $this->load->model("trends_model", "", TRUE);
        $this->load->model("sectoral_statistics_model", "", TRUE);
        $this->load->model("partnerships_model", "", TRUE);
        $this->load->model("consolidate_model", "", TRUE);
        $this->load->model("csr_model", "", TRUE);
        $this->load->model("trainings_model", "", TRUE);
        $this->load->model("performances_model", "", TRUE);
        $this->load->model("leave_schedule_model", "", TRUE);
        $this->load->model("r_n_d_model", "", TRUE);
        $this->load->model("opportunities_model", "", TRUE);
        $this->load->model("settings/tabs_model", "", TRUE);
        $this->load->model("settings/tab_cats_model", "", TRUE);

        $this->template = array(
            'table_open' => '<table style=\'border:5px;border-style:solid;width: 100%;\'>',
            'heading_row_start' => '<tr style=\'background-color:#ccccff;text-transform:capitalize\'>',
            'row_start' => '<tr style="background-color:#eeefff;">',
            'row_alt_start' => '<tr style="background-color:#deefff;">'
        );

        $this->table->set_template($this->template);
        $this->myConfig['uri_segment'] = 2;
        $this->myConfig['per_page'] = '100';

        $this->const['hits'] = $this->kim_model->getHitCount();
    }

    function index($cat=1, $tab=0, $message="") {
        $query = $this->kim_model->getAll(FALSE);
        $data['membership_system'] = $query['membership_system'];
        $data["cats"] = $this->tab_cats_model->getAll();
        $data['all_tabs'] = $this->tabs_model->getAll(FALSE, $cat);
        $data["title"] = "- Desktop";
        $data["wide"] = TRUE;
        $this->load->view('templates/header', $data);
        $data['tab'] = $tab;
        $data['message'] = urldecode($message);
        $this->load->view('admin/mis', $data);
        $this->load->view('templates/footer', $this->const);
    }

    function applicantProfile($username, $div) {
        $row = $this->consolidate_model->getApplicants($username);
        if (count($row) == 0) {
            $row['username'] = $username;
            $row['errors'] = TRUE;
        } else {
            $row = $row[0];
        }
        $row['div'] = $div;
        $this->load->view("admin/applicant_profile", $row);
    }

    function appointments($field=NULL, $search=NULL, $message="") {
        $data['message'] = urldecode($message);
        $query = $this->appointments_model->adminGetAll($field, $search);
        $this->myConfig['total_rows'] = count($query);
        $this->myConfig['base_url'] = base_url() . "index.php?/admin_mis/appointments";
        $this->pagination->initialize($this->myConfig);
        $data['pagina'] = $this->pagination->create_links();
        $this->table->set_heading(array('Date Added', 'To where', "Person to see", 'When', 'Accombanied by', 'Agenda', "More"));
        $data['tablet'] = $this->table->generate($query);
        $this->load->view("mis/appointments", $data);
    }

    function deleteAppointment($tid) {
        $row = $this->appointments_model->delete($tid);
        redirect("admin_mis/index/" . $this->tabs_model->getOrder("appointments") . "/Record deleted");
    }

    function innovations($field=NULL, $search=NULL, $message="") {
        $data['message'] = urldecode($message);
        $query = $this->innovations_model->adminGetAll($field, $search);
        $this->myConfig['total_rows'] = count($query);
        $this->myConfig['base_url'] = base_url() . "index.php?/admin_mis/innovations";
        $this->pagination->initialize($this->myConfig);
        $data['pagina'] = $this->pagination->create_links();
        $this->table->set_heading(array('Date Added', 'Innovation', 'Beneficiaries', 'Business case', 'File', "More Details"));
        $data['tablet'] = $this->table->generate($query);
        $this->load->view("mis/innovations", $data);
    }

    function deleteInnovation($tid) {
        $row = $this->innovations_model->delete($tid);
        redirect("admin_mis/index/" . $this->tabs_model->getOrder("innovations") . "/Record deleted");
    }

    function documents($parent="0", $message="") {
        $expand_icon = "<img src='" . base_url() . "/images/expand.png' alt='Expand'/>";
        $shrink_icon = "<img src='" . base_url() . "/images/shrink.png' alt='Shrink'/>";
        $word_icon = "<img src='" . base_url() . "/images/word.png' alt='Ms Word'/>";
        $pdf_icon = "<img src='" . base_url() . "/images/pdf.png' alt='PDF'/>";
        $folder_icon = "<img src='" . base_url() . "/images/folder.png' alt='Folder'/>";
        $data['message'] = urldecode($message);
        $parentQuery = $this->document_types_model->getAll(NULL, $parent);
        $query = $this->document_types_model->getAll($parent);
        $htmlstr = "";
        if ($parent === "0") {
            //  $htmlstr .= "<a href='javascript:addDocType(0)'>Add category</a>\n";
        } else {
            $docquery = $this->documents_model->adminGetAll($parentQuery[0]['tid']);
            $query = $this->document_types_model->getAll($parentQuery[0]['tid']);
            $htmlstr.="<a href='javascript:loadUrl(\"#docId" . $parentQuery[0]['tid'] . "\",\"" . base_url() . "index.php?/admin_mis/docListItem/" . $parentQuery[0]['tid'] . "\")'>$shrink_icon</a> $folder_icon " . $parentQuery[0]['name'] . " (" . count($docquery) . " documents, " . count($query) . " folders)  <a href='javascript:loadUrl(\"#new_doc\",\"" . base_url() . "index.php?/new_info/newDoc/" . $parentQuery[0]['tid'] . "\")'>Add document</a>";
        }
        $htmlstr .= "<ol type='1'>\n";
        $docquery = $this->documents_model->adminGetAll($parent);
        foreach ($docquery as $docrow) {
            $icon = strpos($docrow['file_path'], ".pdf") == FALSE ? $word_icon : $pdf_icon;
            $htmlstr.="<li> $icon " . $docrow['descr'] . " " . $docrow['file_path'] . " <a href='javascript:gotoUrl(\"" . base_url() . "index.php?/admin_mis/deleteDoc/" . $docrow['tid'] . "\",\"Are you sure to delete this document?\")'>Delete</a> <a href='javascript:loadUrl(\"#doc_result\",\"" . base_url() . "index.php?/more_info/docInfo/" . $docrow['tid'] . "\")'>info</a></li>\n";
        }
        foreach ($query as $row) {
            $docquery = $this->documents_model->adminGetAll($row['tid']);
            $query = $this->document_types_model->getAll($row['tid']);
            $htmlstr.="<li id='docId" . $row['tid'] . "'> <a href='javascript:loadUrl(\"#docId" . $row['tid'] . "\",\"" . base_url() . "index.php?/admin_mis/documents/" . $row['tid'] . "\")'>$expand_icon</a> $folder_icon " . $row['name'] . " (" . count($docquery) . " documents, " . count($query) . " folders) <a href='javascript:loadUrl(\"#new_doc\",\"" . base_url() . "index.php?/new_info/newDoc/" . $row['tid'] . "\")'>Add document</a></li>\n";
        }
        $htmlstr.= "</ol>\n";
        $data['tablet'] = $htmlstr;
        if ($parent === "0") {
            $this->load->view("mis/documents", $data);
        } else {
            echo $data["tablet"];
        }
    }

    function docListItem($tid) {//for use after hiding  a childs of a list item
        $query = $this->document_types_model->getAll(NULL, $tid);
        $row = $query[0];
        $docquery = $this->documents_model->adminGetAll($row['tid']);
        $query = $this->document_types_model->getAll($row['tid']);
        $expand_icon = "<img src='" . base_url() . "/images/expand.png' alt='Expand'/>";
        $folder_icon = "<img src='" . base_url() . "/images/folder.png' alt='Folder'/>";
        echo "<a href='javascript:loadUrl(\"#docId" . $row['tid'] . "\",\"" . base_url() . "index.php?/admin_mis/documents/" . $row['tid'] . "\")'>$expand_icon</a> $folder_icon " . $row['name'] . " (" . count($docquery) . " documents, " . count($query) . " folders) <a href='javascript:loadUrl(\"#new_doc\",\"" . base_url() . "index.php?/new_info/newDoc/" . $row['tid'] . "\")'>Add document</a>";
    }

    function deleteDoc($tid) {
        $row = $this->documents_model->delete($tid);
        redirect("admin_mis/index/" . $this->tabs_model->getOrder("documents") . "/Document deleted");
    }

    function letters($field=NULL, $search=NULL, $message="") {
        $data['message'] = urldecode($message);
        $query = $this->letters_model->adminGetAll($field, $search);
        $this->myConfig['total_rows'] = count($query);
        $this->myConfig['base_url'] = base_url() . "index.php?/admin_mis/letters";
        $this->pagination->initialize($this->myConfig);
        $data['pagina'] = $this->pagination->create_links();
        $this->table->set_heading(array('Date Added', 'Subject', 'Sent to', 'Date Sent', 'File', 'More Details'));
        $data['tablet'] = $this->table->generate($query);
        $this->load->view("mis/letters", $data);
    }

    function deleteLetter($tid) {
        $row = $this->letters_model->delete($tid);
        redirect("admin_mis/index/" . $this->tabs_model->getOrder("letters") . "/Record deleted");
    }

    function csr($field=NULL, $search=NULL, $message="") {
        $data['message'] = urldecode($message);
        $query = $this->csr_model->adminGetAll($field, $search);
        $this->myConfig['total_rows'] = count($query);
        $this->myConfig['base_url'] = base_url() . "index.php?/admin_mis/csr";
        $this->pagination->initialize($this->myConfig);
        $data['pagina'] = $this->pagination->create_links();
        $this->table->set_heading(array('Date Added', 'Nature of events', 'Date participated', 'Targets', 'File/Image', "More Details"));
        $data['tablet'] = $this->table->generate($query);
        $this->load->view("mis/csr", $data);
    }

    function deleteCsr($tid) {
        $row = $this->csr_model->delete($tid);
        redirect("admin_mis/index/" . $this->tabs_model->getOrder("csr") . "/Record deleted");
    }

    function debts($field=NULL, $search=NULL, $message="") {
        $data['message'] = urldecode($message);
        $data["sbus"] = $this->consolidate_model->getDepartments();
        $query = $this->debts_model->adminGetAll($field, $search);
        $this->myConfig['total_rows'] = count($query);
        $this->myConfig['base_url'] = base_url() . "index.php?/admin_mis/debts";
        $this->pagination->initialize($this->myConfig);
        $data['pagina'] = $this->pagination->create_links();
        $this->table->set_heading(array('Date Added', 'Department', 'Debtor', 'Transaction date', 'Amount paid', 'Amount Owed', 'Date payment is due', 'Relationship manager', "More Details"));
        $data['tablet'] = $this->table->generate($query);
        $this->load->view("mis/debts", $data);
    }

    function deleteDebt($tid) {
        $row = $this->debts_model->delete($tid);
        redirect("admin_mis/index/" . $this->tabs_model->getOrder("debts") . "/Record deleted");
    }

    function proposals($field=NULL, $search=NULL, $message="") {
        $data['message'] = urldecode($message);
        $query = $this->proposals_model->adminGetAll($field, $search);
        $this->myConfig['total_rows'] = count($query);
        $this->myConfig['base_url'] = base_url() . "index.php?/admin_mis/proposals";
        $this->pagination->initialize($this->myConfig);
        $data['pagina'] = $this->pagination->create_links();
        $this->table->set_heading(array('Date Added', 'Title', 'Organization', "Date Sent", 'Date advertised', 'File', 'More Details'));
        $data['tablet'] = $this->table->generate($query);
        $this->load->view("mis/proposals", $data);
    }

    function deleteProposal($tid) {
        $row = $this->proposals_model->delete($tid);
        redirect("admin_mis/index/" . $this->tabs_model->getOrder("proposals") . "/Record deleted");
    }

    function assets($field=NULL, $search=NULL, $message="") {
        $data['message'] = urldecode($message);
        $query = $this->assets_model->adminGetAll($field, $search);
        $data["department"] = $this->consolidate_model->getDepartments();
        $this->myConfig['total_rows'] = count($query);
        $this->myConfig['base_url'] = base_url() . "index.php?/admin_mis/assets";
        $this->pagination->initialize($this->myConfig);
        $data['pagina'] = $this->pagination->create_links();
        $this->table->set_heading(array('Date Added', 'Asset', 'Serial no.', 'Department', 'Purchased by', 'Date Purchased', 'Quantity', 'Cost/Item', "More Details"));
        $data['tablet'] = $this->table->generate($query);
        $this->load->view("mis/assets", $data);
    }

    function deleteAsset($tid) {
        $row = $this->assets_model->delete($tid);
        redirect("admin_mis/index/" . $this->tabs_model->getOrder("assets") . "/Record deleted");
    }

    function bids($field=NULL, $search=NULL, $message="") {
        $data['message'] = urldecode($message);
        $query = $this->bids_model->adminGetAll($field, $search);
        $this->myConfig['total_rows'] = count($query);
        $this->myConfig['base_url'] = base_url() . "index.php?/admin_mis/bids";
        $this->pagination->initialize($this->myConfig);
        $data['pagina'] = $this->pagination->create_links();
        $this->table->set_heading(array('Date Added', 'Bid No', 'Company Name', 'Where advertised', 'Date Advertised', 'Description', 'Bid value', "More Details"));
        $data['tablet'] = $this->table->generate($query);
        $this->load->view("mis/bids", $data);
    }

    function deleteBid($tid) {
        $row = $this->bids_model->delete($tid);
        redirect("admin_mis/index/" . $this->tabs_model->getOrder("bids") . "/Record deleted");
    }

    function concepts($field=NULL, $search=NULL, $message="") {
        $data['message'] = urldecode($message);
        $query = $this->concepts_model->adminGetAll($field, $search);
        $this->myConfig['total_rows'] = count($query);
        $this->myConfig['base_url'] = base_url() . "index.php?/admin_mis/concepts";
        $this->pagination->initialize($this->myConfig);
        $data['pagina'] = $this->pagination->create_links();
        $this->table->set_heading(array('Date Added', 'Title', 'Sent to', 'Date sent/submitted', 'Contacts', 'File', "More Details"));
        $data['tablet'] = $this->table->generate($query);
        $this->load->view("mis/concepts", $data);
    }

    function deleteConcept($tid) {
        $row = $this->concepts_model->delete($tid);
        redirect("admin_mis/index/" . $this->tabs_model->getOrder("concepts") . "/Record deleted");
    }

    function opis($field=NULL, $search=NULL, $message="") {
        $data['message'] = urldecode($message);
        $query = $this->opis_model->adminGetAll($field, $search);
        $this->myConfig['total_rows'] = count($query);
        $this->myConfig['base_url'] = base_url() . "index.php?/admin_mis/opis";
        $data["clients"] = $this->consolidate_model->getClients();
        $data["bus_types"] = $this->consolidate_model->getBusinessTypes();
        ;
        $this->pagination->initialize($this->myConfig);
        $data['pagina'] = $this->pagination->create_links();
        $this->table->set_heading(array('Date Added', 'Company Name', 'Business Type', 'Year Assessed', 'Champions Trained', 'Training Year', 'Awards won', 'Relationship manager', "More Details"));
        $data['tablet'] = $this->table->generate($query);
        $this->load->view("mis/opis", $data);
    }

    function deleteOpi($tid) {
        $row = $this->opis_model->delete($tid);
        redirect("admin_mis/index/" . $this->tabs_model->getOrder("opis") . "/Record deleted");
    }

    function trends($field=NULL, $search=NULL, $message="") {
        $data['message'] = urldecode($message);
        $query = $this->trends_model->adminGetAll($field, $search);
        $data["sbus"] = $this->consolidate_model->getDepartments();
        $types = $this->consolidate_model->getServiceTypes();
        $data["serv_types"] = $types;
        $types = $this->consolidate_model->getClients();
        $data["clients"] = $types;
        $this->myConfig['total_rows'] = count($query);
        $this->myConfig['base_url'] = base_url() . "index.php?/mis/trends";
        $this->pagination->initialize($this->myConfig);
        $data['pagina'] = $this->pagination->create_links();
        $this->table->set_heading(array('Date Added', 'Client Name', 'SBU', 'Type of Service', 'Date prequalified', 'Engagement From', 'Engagement To', "More Details"));
        $data['tablet'] = $this->table->generate($query);
        $this->load->view("mis/trends", $data);
    }

    function clientsTree($sbu="0", $client="0", $message="") {
        $expand_icon = "<img src='" . base_url() . "images/expand.png' alt='Expand'/>";
        $shrink_icon = "<img src='" . base_url() . "images/shrink.png' alt='Shrink'/>";
        $data['message'] = urldecode($message);
        $htmlstr = "";
        if ($sbu === "0" && $client === "0") {//the very initial request
            $sbuquery = $this->sbus_model->getAllMini();
            $htmlstr .= "<ol type='1'>\n";
            foreach ($sbuquery as $row) {
                $cltquery = $this->trends_model->getSbuClients($row['tid']);
                $htmlstr.="<li id='sbuId" . $row['tid'] . "'> <a href='javascript:loadUrlSlow(\"#sbuId" . $row['tid'] . "\",\"" . base_url() . "index.php?/admin_mis/clientsTree/" . $row['tid'] . "\")'>$expand_icon</a> " . $row['name'] . " (" . count($cltquery) . " clients) <a href='javascript:loadUrlSlow(\"#trends_result\",\"" . base_url() . "index.php?/admin_mis/clientsAdd/" . $row['tid'] . "\")'>Add client</a> </li>\n";
            }
            $htmlstr.="</ol>\n";
            $data['tablet'] = $htmlstr;
            $this->load->view("mis/trendsTree", $data);
        } else if ($sbu != "0" && $client === "0") {//expands a department sbu
            $sbuquery = $this->sbus_model->getAllMini($sbu);
            $sburow = $sbuquery[0];
            $cltquery = $this->trends_model->getSbuClients($sbu);
            $htmlstr.="<a href='javascript:loadUrlSlow(\"#sbuId" . $sburow['tid'] . "\",\"" . base_url() . "index.php?/admin_mis/clientsTreeShrink/" . $sburow['tid'] . "\")'>$shrink_icon</a> " . $sburow['name'] . " (" . count($cltquery) . " clients) <a href='javascript:loader(\"#trends_result\",\"" . base_url() . "index.php?/admin_mis/clientsAdd/" . $sburow['tid'] . "\")'>Add client</a> \n";
            $cltquery = $this->trends_model->getSbuClients($sbu);
            $htmlstr .= "<ol type='1'>\n";
            foreach ($cltquery as $row) {
                $trequery = $this->trends_model->getAllMini(NULL, $sbu, $row['client_id']);
                $htmlstr.="<li id='cltId" . $row['client_id'] . "'> <a href='javascript:loadUrlSlow(\"#cltId" . $row['client_id'] . "\",\"" . base_url() . "index.php?/admin_mis/clientsTree/$sbu/" . $row['client_id'] . "\")'>$expand_icon</a> " . $row['client_name'] . " (" . count($trequery) . " services)</li>\n";
            }
            $htmlstr.="</ol>\n";
            $data['tablet'] = $htmlstr;
            echo $data['tablet'];
        } else if ($client != "0") {//expands a client
            $cltquery = $this->clients_model->getAllMini($client);
            $cltrow = $cltquery[0];
            $trequery = $this->trends_model->getAllMini(NULL, $sbu, $client);
            $htmlstr.="<a href='javascript:loadUrlSlow(\"#cltId" . $cltrow['tid'] . "\",\"" . base_url() . "index.php?/admin_mis/clientsTreeShrink/0/" . $cltrow['tid'] . "\")'>$shrink_icon</a> " . $cltrow['name'] . " (" . count($trequery) . " services)\n";
            $trequery = $this->trends_model->getAllMini(NULL, $sbu, $client);
            $htmlstr .= "<ol type='1'>\n";
            foreach ($trequery as $row) {
                $htmlstr.="<li>" . $row['service_type'] . " " . $row['more'] . "\n";
            }
            $htmlstr.="</ol>\n";
            $data['tablet'] = $htmlstr;
            echo $data['tablet'];
        } else {
            echo "No matching condition!";
        }
    }

    function clientsTreeShrink($sbu="0", $client="0") {
        $expand_icon = "<img src='" . base_url() . "/images/expand.png' alt='Expand'/>";
        $htmlstr = "";
        if ($sbu != "0" && $client === "0") {//shrinks a department sbu
            $sbuquery = $this->sbus_model->getAllMini($sbu);
            $sburow = $sbuquery[0];
            $cltquery = $this->trends_model->getSbuClients($sbu);
            $htmlstr.="<a href='javascript:loadUrlSlow(\"#sbuId" . $sburow['tid'] . "\",\"" . base_url() . "index.php?/admin_mis/clientsTree/" . $sburow['tid'] . "\")'>$expand_icon</a> " . $sburow['name'] . " (" . count($cltquery) . " clients) <a href='javascript:loader(\"#trends_result\",\"" . base_url() . "index.php?/admin_mis/clientsAdd/" . $sburow['tid'] . "\")'>Add client</a> \n";
            $data['tablet'] = $htmlstr;
            echo $data['tablet'];
        } else if ($client != "0") {//shrinks a client
            $cltquery = $this->clients_model->getAllMini($client);
            $cltrow = $cltquery[0];
            $trequery = $this->trends_model->getAllMini(NULL, $sbu, $client);
            $htmlstr.="<a href='javascript:loadUrlSlow(\"#cltId" . $cltrow['tid'] . "\",\"" . base_url() . "index.php?/admin_mis/clientsTree/0/" . $cltrow['tid'] . "\")'>$expand_icon</a> " . $cltrow['name'] . "(" . count($trequery) . " services) \n";
            $data['tablet'] = $htmlstr;
            echo $data['tablet'];
        } else {
            echo "No matching condition!";
        }
    }

    function clientsAdd($sbu) {
        $data["sbu"] = $sbu;
        $types = $this->consolidate_model->getServiceTypes();
        $data["serv_types"] = $types;
        $types = $this->consolidate_model->getClients();
        $data["clients"] = $types;
        $this->load->view("mis/new_info/addClient", $data);
    }

    function deleteTrend($tid) {
        $row = $this->trends_model->delete($tid);
        redirect("admin_mis/index/" . $this->tabs_model->getOrder("trends") . "/Record deleted");
    }

    function partnerships($field=NULL, $search=NULL, $message="") {
        $data['message'] = urldecode($message);
        $data["department"] = $this->consolidate_model->getDepartments();
        $query = $this->partnerships_model->adminGetAll($field, $search);
        $this->myConfig['total_rows'] = count($query);
        $this->myConfig['base_url'] = base_url() . "index.php?/mis/partnerships";
        $this->pagination->initialize($this->myConfig);
        $data['pagina'] = $this->pagination->create_links();
        $this->table->set_heading(array('Date Added', 'Department', 'Company Name', 'Type of Partnership', 'Partner From', 'Business case', "More Details"));
        $data['tablet'] = $this->table->generate($query);
        $this->load->view("mis/partnerships", $data);
    }

    function deletePartnership($tid) {
        $row = $this->partnerships_model->delete($tid);
        redirect("admin_mis/index/" . $this->tabs_model->getOrder("partnerships") . "/Record deleted");
    }

    function sectoral_statistics($field=NULL, $search=NULL, $message="") {
        $data['message'] = urldecode($message);
        $query = $this->sectoral_statistics_model->adminGetAll($field, $search);
        $types = $this->consolidate_model->getOrgTypes();
        $data["orgs"] = $types;
        $this->myConfig['total_rows'] = count($query);
        $this->myConfig['base_url'] = base_url() . "index.php?/mis/sectoral_statistics";
        $this->pagination->initialize($this->myConfig);
        $data['pagina'] = $this->pagination->create_links();
        $this->table->set_heading(array('Date Added', 'Organizational Name', 'Category', 'Position', "More Details"));
        $data['tablet'] = $this->table->generate($query);
        $this->load->view("mis/sectoral_statistics", $data);
    }

    function deleteSectoral_statistic($tid) {
        $row = $this->sectoral_statistics_model->delete($tid);
        redirect("admin_mis/index/" . $this->tabs_model->getOrder("sectoral_statistics") . "/Record deleted");
    }

    function trainings($field=NULL, $search=NULL, $message="") {
        $data['message'] = urldecode($message);
        $data["department"] = $this->consolidate_model->getDepartments();
        $query = $this->trainings_model->adminGetAll($field, $search);
        $this->myConfig['total_rows'] = count($query);
        $this->myConfig['base_url'] = base_url() . "index.php?/admin_mis/trainings";
        $this->pagination->initialize($this->myConfig);
        $data['pagina'] = $this->pagination->create_links();
        $this->table->set_heading(array('Date Added', 'Department', 'Topic', 'Resource person', 'Cost', 'Contact', 'Date due', "More Details"));
        $data['tablet'] = $this->table->generate($query);
        $this->load->view("mis/trainings", $data);
    }

    function deleteTraining($tid) {
        $row = $this->trainings_model->delete($tid);
        redirect("admin_mis/index/" . $this->tabs_model->getOrder("trainings") . "/Record deleted");
    }

    function performances($field=NULL, $search=NULL, $message="") {
        $data['message'] = urldecode($message);
        $data["department"] = $this->consolidate_model->getDepartments();
        $query = $this->performances_model->adminGetAll($field, $search);
        $this->myConfig['total_rows'] = count($query);
        $this->myConfig['base_url'] = base_url() . "index.php?/admin_mis/performances";
        $this->pagination->initialize($this->myConfig);
        $data['pagina'] = $this->pagination->create_links();
        $this->table->set_heading(array('Date Added', 'Department', 'Annual budget', 'Quarter1', 'Quarter2', 'Quarter3', 'Quarter4', "More Details"));
        $data['tablet'] = $this->table->generate($query);
        $this->load->view("mis/performances", $data);
    }

    function deletePerformance($tid) {
        $row = $this->performances_model->delete($tid);
        redirect("admin_mis/index/" . $this->tabs_model->getOrder("performances") . "/Record deleted");
    }

    function leaveSchedule($field=NULL, $search=NULL, $message="") {
        $data['message'] = urldecode($message);
        $data["department"] = $this->consolidate_model->getDepartments();
        $query = $this->leave_schedule_model->adminGetAll($field, $search);
        $this->myConfig['total_rows'] = count($query);
        $this->myConfig['base_url'] = base_url() . "index.php?/admin_mis/leaveSchedule";
        $this->pagination->initialize($this->myConfig);
        $data['pagina'] = $this->pagination->create_links();
        $this->table->set_heading(array('Date Added', 'PNO', 'Names', 'Department', 'Type of leave', 'No of days', 'Replacement', 'Start date', 'End date', 'Handover note', "More Details"));
        $data['tablet'] = $this->table->generate($query);
        $this->load->view("mis/leaveSchedule", $data);
    }

    function deleteLeaveSchedule($tid) {
        $row = $this->leave_schedule_model->delete($tid);
        redirect("admin_mis/index/" . $this->tabs_model->getOrder("leaveSchedule") . "/Record deleted");
    }

    function r_n_d($field=NULL, $search=NULL, $message="") {
        $data['message'] = urldecode($message);
        $query = $this->r_n_d_model->adminGetAll($field, $search);
        $this->myConfig['total_rows'] = count($query);
        $this->myConfig['base_url'] = base_url() . "index.php?/admin_mis/r_n_d";
        $this->pagination->initialize($this->myConfig);
        $data['pagina'] = $this->pagination->create_links();
        $this->table->set_heading(array('Date Added', 'Title', 'Target', 'Cost', 'Report', 'More Details'));
        $data['tablet'] = $this->table->generate($query);
        $this->load->view("mis/r_n_d", $data);
    }

    function deleteR_n_d($tid) {
        $row = $this->r_n_d_model->delete($tid);
        redirect("admin_mis/index/" . $this->tabs_model->getOrder("r_n_d") . "/Record deleted");
    }

    function opportunities($field=NULL, $search=NULL, $message="") {
        $data['message'] = urldecode($message);
        $query = $this->opportunities_model->adminGetAll($field, $search);
        $this->myConfig['total_rows'] = count($query);
        $this->myConfig['base_url'] = base_url() . "index.php?/admin_mis/opportunities";
        $this->pagination->initialize($this->myConfig);
        $data['pagina'] = $this->pagination->create_links();
        $this->table->set_heading(array('Date Added', 'Opportunity', 'Source', 'Beneficiary', 'Approach', 'More Details'));
        $data['tablet'] = $this->table->generate($query);
        $this->load->view("mis/opportunities", $data);
    }

    function deleteOpportunities($tid) {
        $row = $this->opportunities_model->delete($tid);
        redirect("admin_mis/index/" . $this->tabs_model->getOrder("opportunities") . "/Record deleted");
    }

    function comingSoon($coming) {
        echo "$coming Coming Soon! Watch This Space";
    }

}

?>